#include "serial.h"
#include "lib.h"

#define DBGU_BASE (0xFFFFF200)
#define DBGU_SR   (volatile unsigned int*)(DBGU_BASE + 0x14)
#define DBGU_THR  (volatile unsigned int*)(DBGU_BASE + 0x1C)

#define TXRDY (1 << 1)

void write(char *str)
{
  while(*str != '\0') {
    writechar(*str);
    str++;
  }
}
//------------------------------------------------------------------------------
void writechar(char ch)
{
  while(!(*DBGU_SR & TXRDY));
  *DBGU_THR = ch;
}
//------------------------------------------------------------------------------
void kprintf (char *str, ...)
{
  char dest [1024];
  vsnprintf(dest, 1024, str, ((int *) &str) + 1);
  write(dest);
}
//------------------------------------------------------------------------------

